﻿using AutoMapper;
using JIESHINet.Model.Entity;
using JIESHINet.Model.Vo;

namespace JIESHINet.Extensions
{
    /// <summary>
    /// Auto的视图模型转换配置文件。
    /// </summary>
    public class CustomProfile: Profile
    {
        /// <summary>
        /// 配置构造函数，用来创建关系映射
        /// </summary>
        public CustomProfile() {

            CreateMap<User, UserVo>()
                    .ForMember(x => x.UserName, a => a.MapFrom(d => d.Name));
            CreateMap<UserVo, User>()
                   .ForMember(x => x.Name, a => a.MapFrom(d => d.UserName));

            CreateMap<Role, RoleVo>()
                   .ForMember(x => x.RoleName, a => a.MapFrom(d => d.Name));
            CreateMap<RoleVo, Role>()
                   .ForMember(x => x.Name, a => a.MapFrom(d => d.RoleName));

        }
    }
}
